package ${ftl.packageName}.${cgH.moduleName};
<#assign en =0 />
<#assign ac =3 />
<#assign cf =4 />
<#assign dto =8 />
import ${mList[en].packageName}.${cgH.moduleName}.${tc.entityName}${mList[en].classPostfix};
import ${mList[ac].packageName}.${cgH.moduleName}.${tc.entityName}${mList[ac].classPostfix};
import ${mList[cf].packageName}.${cgH.moduleName}.${tc.entityName}${mList[cf].classPostfix};
import ${mList[dto].packageName}.${cgH.moduleName}.${tc.entityName}${mList[dto].classPostfix};
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
<#if "${cgH.isTree =='1'}">
import com.stars.common.tree.TreeJson;
import java.util.List;
<#else >
import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
</#if>
/**
 * @Title: ${cgH.content} mybatis dao
 * @author dj
 * @date ${tc.createTime}
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/${tc.entityName?uncap_first}Ctl")
@Api(tags ="${cgH.content}")
public class ${tc.entityName}${tc.entityPostfix} extends BaseController{
   @Autowired
   private ${tc.entityName}${mList[ac].classPostfix}  ${tc.entityName ? uncap_first}${mList[ac].classPostfix}Impl;
   @Autowired
   private ${tc.entityName}${mList[cf].classPostfix}  ${tc.entityName ? uncap_first}${mList[cf].classPostfix}Impl;

<#if "${cgH.isTree =='1'}">
    /**
    * 保存
    * @param treeJson
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "${cgH.content}"+ BaseMsg.MODULAR_ADD,notes = "${cgH.content}"+BaseMsg.MODULAR_ADD)
    @Log(detail = "${cgH.content}"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg add${tc.entityName}(TreeJson treeJson,HttpServletRequest request) throws Exception{
        setAddBaseOrg(treeJson,request,null);
        return ${tc.entityName ? uncap_first}${mList[cf].classPostfix}Impl.saveTree(treeJson);
    }
    /**
    * 获取全部的树形数据
    *
    * @return
    * @throws Exception
    */
    @PostMapping("/findTree")
    @ApiOperation(value = "获取全部的资源数据",notes = "获取全部的资源数据")
    @Log(detail = "${cgH.content}"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
    public ResultMsg findTree(${tc.entityName}${mList[dto].classPostfix} ${tc.entityName ? uncap_first}${mList[dto].classPostfix},HttpServletRequest request) throws Exception {
        setSystemApp(${tc.entityName ? uncap_first}${mList[dto].classPostfix},request);
        List<${tc.entityName}${mList[dto].classPostfix}> treeList = ${tc.entityName ? uncap_first}${mList[ac].classPostfix}Impl.findTreeList(${tc.entityName ? uncap_first}${mList[dto].classPostfix});
        return ResultMsg.success(treeList);
    }

<#else >
   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "${cgH.content}"+BaseMsg.MODULAR_PAGE,notes ="${cgH.content}"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "${cgH.content}"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<${tc.entityName}${mList[dto].classPostfix}> page${tc.entityName}List(Integer pageNum, Integer pageSize, ${tc.entityName}${mList[dto].classPostfix} dto,HttpServletRequest request) throws Exception{
        setSystemApp(dto,request);
        return ${tc.entityName ? uncap_first}${mList[ac].classPostfix}Impl.pageList(pageNum,pageSize,dto);

   }

    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "${cgH.content}"+ BaseMsg.MODULAR_ADD,notes = "${cgH.content}"+BaseMsg.MODULAR_ADD)
    @Log(detail = "${cgH.content}"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg add${tc.entityName}(@Validated({AddView.class}) ${tc.entityName}${mList[en].classPostfix} entityName,HttpServletRequest request) throws Exception{
        <#if "${cgH.isCreateAppOrg =='1'}">setAddBase(entityName,request,null);<#elseif "${cgH.isCreateAppOrg =='2'}">setAddCompany(entityName,request,null);<#elseif "${cgH.isCreateAppOrg =='3'}">setAddBaseOrg(entityName,request,null);<#elseif "${cgH.isCreateAppOrg =='4'}">setAddBaseApp(entityName,request);</#if>
        return ${tc.entityName ? uncap_first}${mList[cf].classPostfix}Impl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "${cgH.content}"+ BaseMsg.MODULAR_UPDATE,notes = "${cgH.content}"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "${cgH.content}"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg update${tc.entityName}(@Validated({UpdateView.class}) ${tc.entityName}${mList[en].classPostfix} updateEntityDto,HttpServletRequest request) throws Exception{
        ${tc.entityName}${mList[en].classPostfix} entity = ${tc.entityName ? uncap_first}${mList[ac].classPostfix}Impl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.UPDATE);
        setUpdateBase(entity,request);
        return ${tc.entityName ? uncap_first}${mList[cf].classPostfix}Impl.updateSelectiveById(entity);
    }

    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "${cgH.content}"+ BaseMsg.MODULAR_FIND_ID,notes = "${cgH.content}"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "${cgH.content}"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg find${tc.entityName}ById(String id) throws Exception{
        ${tc.entityName}${mList[en].classPostfix} entityName = ${tc.entityName ? uncap_first}${mList[ac].classPostfix}Impl.selectById(id);
         return ResultMsg.success(entityName);
    }

     /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "${cgH.content}"+BaseMsg.MODULAR_DEL,notes ="${cgH.content}"+BaseMsg.MODULAR_DEL)
     @Log(detail ="${cgH.content}"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg del${tc.entityName}ById(String ids) throws Exception{
        ${tc.entityName ? uncap_first}${mList[cf].classPostfix}Impl.deleteByIdS(ids.split(BaseConstant.SPOT));
        return ResultMsg.success();
     }

</#if>
}